package {
	/**
	 * @author guido
	 */
	public class Enemy extends PhysicsEntity {
		import net.flashpunk.graphics.Spritemap;
		import net.flashpunk.FP;
		import net.flashpunk.utils.Input;
		import net.flashpunk.utils.Key;
		
		public var remainingStunTime : int = 0;

		[Embed(source = 'assets/chunli.png')]
		private const CHUNLI : Class;
		public var chunli : Spritemap = new Spritemap(CHUNLI, 88, 107);

		public function Enemy(x:Number, y:Number) {
			setHitbox(88, 107);
			chunli.add("stand", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
				11, 12, 13, 14, 15], 20, true);
			chunli.add("dizzy", [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
				36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], 20, true);
			graphic = chunli;

			// Here I do the same thing by just assigning Player's properties.
			width = 88;
			height = 107;
			this.x = x;
			this.y = y;
			chunli.play("stand");
			chunli.flipped = true;
			type = "collidable";
		}

		public function stun() : void {
			chunli.play("dizzy");
			remainingStunTime = 60;
		}

		override public function update() : void {
			super.update();
			var b : Rock = collide("bullet", x, y) as Rock;

			// Check if b has a value (true if a Bullet was collided with).
			if (b) {
				stun();
				// Call the Bullet's destroy() function.
				b.rebound(this.halfHeight+ this.x, this.halfWidth+this.y);
			}
			if (remainingStunTime > 0) {
				remainingStunTime--;
			}
			if (remainingStunTime == 0) {
				chunli.play("stand");
			}
		}
	}
}
